/**
 * @author Chengzi Xu
 */

package cn.edu.sjtu.stap.sdg;


import cn.edu.sjtu.stap.graph.GraphEdge;
import cn.edu.sjtu.stap.graph.GraphNode;

public class SdgEdge extends GraphEdge {
    private static final long serialVersionUID = 1L;

    private static long edgeCount = 0;

    private SdgEdgeKind kind;

    public SdgEdge(SdgEdgeKind kind, SdgNode from, SdgNode to) {
        super(++edgeCount, from, to);
        setKind(kind);
    }

    public void setKind(SdgEdgeKind kind) {
        if (null == kind) {
            throw new NullPointerException("Flow kind should not be null!");
        }
        this.kind = kind;
    }

    public SdgEdgeKind getKind() {
        return kind;
    }

    public String getName() {
        return kind.getName();
    }

    public void setSourceNode(GraphNode node) {
        if (!(node instanceof SdgNode)) {
            throw new IllegalArgumentException();
        }
        super.setSourceNode(node);
    }

    public void setDestinationNode(GraphNode node) {
        if (!(node instanceof SdgNode)) {
            throw new IllegalArgumentException();
        }
        super.setDestinationNode(node);
    }

    public SdgNode getSourceNode() {
        return (SdgNode) super.getSourceNode();
    }

    public SdgNode getDestinationNode() {
        return (SdgNode) super.getDestinationNode();
    }

    public String toString() {
        StringBuffer s = new StringBuffer();
        s.append("(Sdg Edge Id: ");
        s.append(this.getId());
        s.append(", Name: ");
        s.append(getName());
        s.append(", From: (Node Id: ");
        s.append(this.getSourceNode().getId());
        s.append("), To: (Node Id: ");
        s.append(this.getDestinationNode().getId());
        s.append("))\n");
        return s.toString();
    }
}
